package com.gms.service.placemanager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gms.entity.place.Place;
import com.gms.mapper.placemanager.PlaceMapper;
import com.gms.service.placemanager.PlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, Place> implements PlaceService {

    @Autowired
    private PlaceMapper placeMapper;

    @Override
    public void InsertPlace(Place place) {
        placeMapper.insert(place);
    }

    @Override
    public void DeletePlaceByNo(String place_no) {
        UpdateWrapper<Place> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("place_no",place_no);
        updateWrapper.set("place_state", "已删除");
        placeMapper.update(null, updateWrapper);
    }

    @Override
    public boolean CheckPlaceNo(String place_no) {
        QueryWrapper<Place> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("place_no", place_no);
        queryWrapper.eq("place_state", "可使用");
        Integer integer = placeMapper.selectCount(queryWrapper);
        return integer != 0;
    }

    @Override
    public List<Place> SelectAllPlace() {
        QueryWrapper<Place> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("place_state","可使用");
        return placeMapper.selectList(queryWrapper);
    }

    @Override
    public void UpdatePlace(Place place) {
        placeMapper.updateById(place);
    }

    @Override
    public List<Place> SelectAllPlaceByType(String type) {
        QueryWrapper<Place> queryWrapper = new QueryWrapper<>();
        Map<String,Object> map = new HashMap<>();
        map.put("place_type",type);
        queryWrapper.allEq(map,false);
        return placeMapper.selectList(queryWrapper);
    }

    @Override
    public List<Place> SelectAllPlaceByStorey(String storey) {
        QueryWrapper<Place> queryWrapper = new QueryWrapper<>();
        Map<String,Object> map = new HashMap<>();
        map.put("place_storey",storey);
        queryWrapper.allEq(map,false);
        return placeMapper.selectList(queryWrapper);
    }

    @Override
    public List<Place> SelectAllPlaceByOrder(String type, String storey) {
        QueryWrapper<Place> queryWrapper = new QueryWrapper<>();
        Map<String,Object> map = new HashMap<>();
        map.put("place_state","可使用");
        map.put("place_type",type);
        map.put("place_storey",storey);
        queryWrapper.allEq(map,false);
        return placeMapper.selectList(queryWrapper);
    }


}
